package com.stud.common.utils;

import cn.hutool.core.date.DateUtil;
import lombok.extern.slf4j.Slf4j;

import java.util.Date;
import java.util.Objects;

/**
 * 打印和日志工具
 *
 * @author Stud
 */
@Slf4j
public class LogUtils {
    public static String getBlock(Object msg) {
        if (msg == null) {
            msg = "";
        }
        return "[" + msg + "]";
    }

    public static void realSqlLog(String sql, Object... params) {
        if (log.isDebugEnabled()) {
            if (Objects.isNull(params) || params.length == 0) {
                log.debug("原始sql==" + sql);
                return;
            }
            for (Object param : params) {
                String temp;
                if (param instanceof Date) {
                    temp = DateUtil.formatDateTime((Date) param);
                } else {
                    temp = Toolkit.object2String(param);
                }
                sql = sql.replaceFirst("[?]", "'" + temp + "'");
            }
            log.debug("原始sql==" + sql);
        }
    }
}
